Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale manual control setpoint up/down stick -1 to 1 #15949

Merged
merged 4 commits into from Nov 28, 2022

Conversation

MaEtUgR
Copy link
Member

@MaEtUgR MaEtUgR commented Oct 12, 2020

Describe problem solved by this pull request
Fixes #9331 and works towards a solution for part of #15874

Describe your solution
Rescale manual_control_setpoint.z which represents the throttle stick value from a range of [0,1] to [-1,1].

Describe possible alternatives
I think for nicer usage in all the different modules it would be helpful to extend the Sticks class to provide the common scaling and gestures (is stick below minimum) from one single place.

Test data / coverage
Not yet tested.

Additional context
This is also useful to be able to convert between RC modes (https://www.rc-airplane-world.com/rc-transmitter-modes.html) on the fly without having to recalibrate everything.

@MaEtUgR MaEtUgR requested a review from dagar October 12, 2020 18:11
@MaEtUgR MaEtUgR self-assigned this Oct 12, 2020
@MaEtUgR MaEtUgR changed the title Manual control setpoint 1to1 Scale manual control setpoint up/down stick -1 to 1 Oct 12, 2020
@MaEtUgR MaEtUgR force-pushed the manual-control-setpoint-1to1 branch 2 times, most recently from 418388c to 200a5ef Compare October 13, 2020 08:28
@MaEtUgR MaEtUgR changed the title Scale manual control setpoint up/down stick -1 to 1 [WIP] Scale manual control setpoint up/down stick -1 to 1 Oct 14, 2020
@MaEtUgR
Copy link
Member Author

MaEtUgR commented Nov 3, 2020

Reminder for myself to rebase on https://github.com/Auterion/PX4_firmware_private/pull/661 like discussed. EDIT: ✔️

@MaEtUgR MaEtUgR force-pushed the manual-control-setpoint-1to1 branch 2 times, most recently from 5611a84 to 2aa4edd Compare December 11, 2020 13:07
@MaEtUgR MaEtUgR changed the base branch from master to pr-manual_control_switches_simple December 11, 2020 13:10
@MaEtUgR
Copy link
Member Author

MaEtUgR commented Dec 11, 2020

@dagar

@MaEtUgR MaEtUgR changed the title [WIP] Scale manual control setpoint up/down stick -1 to 1 Scale manual control setpoint up/down stick -1 to 1 Dec 11, 2020
Base automatically changed from pr-manual_control_switches_simple to master December 11, 2020 17:11
@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@tstastny
Copy link
Contributor

tstastny commented Jun 27, 2022

I think for nicer usage in all the different modules it would be helpful to extend the Sticks class to provide the common scaling and gestures (is stick below minimum) from one single place.

I agree with you on this point. Seems a bit dangerous (error prone) that we are re-interpreting these manual controls everywhere they are used.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Jun 28, 2022

I rebased this pr on main and after investigating carefully I suggest using roll, pitch, yaw, and throttle for the naming of the axes because:

The only two disadvantages I see are:

  • For the pitch stick to be consistent with positive values are stick up right it maps to a negative pitch euler angle which is documented and in my eyes acceptable but possibly the main discussion point. I'd suggest to not switch the direction because:
    • Up right stick being positive makes mapping a lot easier
    • Switching throttle and pitch e.g. for RC mode 1 would then also involve switching sign and is more error-prone
    • Staying consistent with the existing direction (also in MAVLink)
  • Stick input usages that completely differ from the conventional way of input might get shuffled when remapping the assignments e.g. for RC Mode 1,2,3,4 which was already the case before and I don't see an easy fix without undue complexity.

For the revamping of the Stick class to adapt and be reusable everywhere I suggest to do a follow-up pull request since this one is about the uORB interface.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Nov 21, 2022

@junwoo091400 Thanks a lot for your review, additional thoughts and suggestions. Your feedback is highly appreciated just slightly on the verbose side 😇

QGC is fetching these values from the RC_CHANNELS message
doesn't depend on changing the definition of MANUAL_CONTROL

I know. The big problem is solving backward compatibility on all sides e.g. QGC, MAVLink to an ambiguous definition that was misused in various out-of-range or other "fits the case" solutions. I explicitly wanted this pr to only solve the PX4 autopilot side and care about MAVLink and QGC in the next step.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Nov 24, 2022

I had to rebase on #20647 and #20537 nothing complicated.

After the feedback from yesterday's dev call I found a good solution for the backward compatibility: I do the same as before but not adjusting the throttle trim parameter. That solves the problem of having an adapted parameter when downgrading but also makes sure that it all works like expected with the default calibration everyone gets through QGC. So the door is open for a new calibration and phasing out the old one.

I tested this again on hardware just to be sure. Also note that even though FMUv5x overflows this pr saves ~230bytes but main is overflowing more than that.

In my eyes this is now good to go 🎉

@junwoo091400
Copy link
Contributor

I found a good solution for the backward compatibility: I do the same as before but not adjusting the throttle trim parameter. That solves the problem of having an adapted parameter when downgrading but also makes sure that it all works like expected with the default calibration everyone gets through QGC.

Ah that's such a good idea! (Took me 10 seconds to understand though haha) Changing the run-time applied trim value, and not modifying the parameter value itself is an elegant solution 👍

I guess we should get the QGC PR in quickly! If you have a QGC dev environment, could you test on a real vehicle with real RC tx/rx whether the QGC PR: mavlink/qgroundcontrol#10497 works as expected (Set Trim to mid-value, not min)?

junwoo091400
junwoo091400 previously approved these changes Nov 24, 2022
Copy link
Contributor

@junwoo091400 junwoo091400 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to formally put in my review, this is a great change! 😉

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Nov 24, 2022

@junwoo091400 Thanks for your review!

I guess we should get the QGC PR in quickly!

I think we shouldn't over-hurry but rather avoid mistakes that could lead to user problems.

If you have a QGC dev environment

I currently don't sorry. But as I wrote in mavlink/qgroundcontrol#10497 (comment) we need to be careful. I'd guess with that pr the trim value doesn't necessarily get set to the middle but to where the throttle stick is at the beginning of the calibration which would be not deterministic and often at the bottom. Also think about the case where someone uses the latest QGC including that change but PX4 1.13 or main from yesterday. It would result in a configuration making half of the stick not work anymore for no reason. Let's go through it cleanly on the QGC side.

To be consistent with all other axes of stick input and avoid future
rescaling confusion.

Note: for the MAVLink message 69 MANUAL_CONTROL it's using the full range
according to the message specs now [-1000,1000].
In review it was requested to have a different name for
manual_control_setpoint.z because of the adjusted range.

I started to investigate what naming is most intuitive and found
that most people recognize the stick axes as roll, pitch, yaw, throttle.
It comes at no surprise because other autopilots
and APIs seem to share this convention.

While changing the code I realized that even within the code base
the axes are usually assigned to a variable with that name or
have comments next to the assignment clarifying the axes
using these names.
This is fully backwards compatible: If the throttle trim is set to
the minimum then it's the legacy calibration and gets
interpreted such that there is no trim and behavior remains as before.
If the trim is set to a different value than the minimum then it gets
used like with all other channels which was unsupported before.
@MaEtUgR MaEtUgR merged commit babe93c into main Nov 28, 2022
@MaEtUgR MaEtUgR deleted the manual-control-setpoint-1to1 branch November 28, 2022 18:25
MaEtUgR pushed a commit to PX4/flight_review that referenced this pull request Nov 28, 2022
MaEtUgR pushed a commit to PX4/flight_review that referenced this pull request Nov 28, 2022
@junwoo091400
Copy link
Contributor

Yayyyy thanks for this @MaEtUgR !!

Jaeyoung-Lim added a commit that referenced this pull request Dec 7, 2022
Jaeyoung-Lim added a commit that referenced this pull request Dec 7, 2022
# Stick positions [-1,1]
# on a common RC mode 1/2/3/4 remote/joystick the stick deflection: -1 is down/left, 1 is up/right
# Note: QGC sends throttle/z in range [0,1000] - [0,1]. The MAVLink input conversion [0,1] to [-1,1] is at the moment kept backwards compatible.
# Positive values are generally used for:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the mappings were vehicle and flight mode agnostic. An MC vehicle in position mode does not roll or pitch - it move forward or left-right. So you've made this very unintuitive except for fixed wing vehicles.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the mappings were vehicle and flight mode agnostic.

I do not agree, previously the naming according to the cartesian coordinate system's axes x, y, z only fully made sense for multirotor position mode where the values moved the drone along the respective body axis. r I could never make sense of.

An MC vehicle in position mode does not roll or pitch - it move forward or left-right.

I agree it doesn't fit entirely and it's in my eyes impossible to find a naming that fully fits every single possible mode, that's why I favored consistency across drone remotes.

So you've made this very unintuitive except for fixed wing vehicles.

I disagree. For someone who never worked with drones before and has no reference from any other project or product you could argue the previous naming was equal as suitable. But this is clearly not the case. As I elaborated in #15949 (comment) people come with previous knowledge and or use a remote of some brand and the roll, pitch, yaw, throttle naming is the most popular and consistent one out in the hobby and industry. So it's not just me who got confused when joining PX4 why it needs to have different naming than everyone else, every time has to think twice about which axis it now is and keep a translation table in the comments but numerous other people I asked and found reference for in the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After 5 years working with PX4 I still had to look up every time what x,y,z and r are linked to, so for me these new namings are massively more intuitive.

Jaeyoung-Lim added a commit that referenced this pull request Dec 13, 2022
sfuhrer pushed a commit that referenced this pull request Dec 29, 2022
Jaeyoung-Lim added a commit that referenced this pull request Dec 29, 2022
Jaeyoung-Lim added a commit that referenced this pull request Jan 4, 2023
@DronecodeBot
Copy link

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/driving-backwards-with-a-boat-rover-in-manual-mode/25714/6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RC: Have all sticks scaled from -1 to 1 in the normalized representation
8 participants